import http from './http.js'

//登录
const login = function login(uId, uPassword) {
    return http.post('/api/login?', {
        username: uId,
        password: uPassword,
    })
}

//注册
const register = function phoneRegister(registerEmail, registerPassword, captcha) {
    return http.post('/api/user', {
        email: registerEmail,
        pwd: registerPassword,
        captcha,
    })

}

//获取邮箱验证码
const emailCapture = function capture(registerEmail) {
    return http.post('/api/user/captcha', {
        email: registerEmail
    }, {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            "token": window.localStorage.getItem('userToken') || "",
        },
    })
}

//找回密码
const forgetPassword = function forgetPassword(username, retrieveCapture, password) {
    return http.post('/api/user/forget', {
        username,
        captcha: retrieveCapture,
        password,
    })
}


//获取所有用户
const allUsers = function allUsers() {
    return http.get('/api/user')
}

export default {
    login,
    register,
    emailCapture,
    allUsers,
    forgetPassword,
}